#include "CCreditsState.h"
#include "CMainMenuState.h"
#include "CGame.h"
#include "SGD Wrappers\CSGD_TextureManager.h"
#include "SGD Wrappers\CSGD_Direct3D.h"
#include "SGD Wrappers\CSGD_DirectInput.h"
#include "SGD Wrappers\CSGD_FModManager.h"
#include "CBitmapFont.h"

CCreditsState::CCreditsState( void )
{

}
CCreditsState::~CCreditsState(void)
{

}
CCreditsState* CCreditsState::GetInstance( void )
{
	//	Lazy instantiation
	static CCreditsState instance;
	return &instance;
}

void CCreditsState::Enter(void)
{
	//m_nMenuSelection = 0;

	m_nFXVolume = CGame::GetInstance()->GetSFXVolume();
	m_nMusicVolume = CGame::GetInstance()->GetMusicVolume();
	m_nMusicPan = CGame::GetInstance()->GetPanVolume();

	//TODO:
	CSGD_FModManager::GetInstance()->SetVolume(m_nBGM,CGame::GetInstance()->GetMusicVolume());
	CSGD_FModManager::GetInstance()->SetPan(m_nBGM,CGame::GetInstance()->GetPanVolume());

	//m_nCursorID = CSGD_TextureManager::GetInstance()->LoadTexture( "resources//graphics//SGD_MenuCursor.png" );

	m_nBGM = CSGD_FModManager::GetInstance()->LoadSound("resources//music//StS_01_prologue_-_cirrus.OGG", FMOD_LOOP_NORMAL);

	YPos[0] = 10   + 500;
	YPos[1] = 60   + 500;
	YPos[2] = 90   + 500;
	YPos[3] = 150  + 500;
	YPos[4] = 180  + 500;
	YPos[5] = 210  + 500;
	YPos[6] = 240  + 500;
	YPos[7] = 270  + 500;
	YPos[8] = 330  + 500;
	YPos[9] = 360  + 500;
	YPos[10] = 420 + 500;
	YPos[11] = 450 + 500;
	YPos[12] = 510 + 500;
	YPos[13] = 540 + 500;
	YPos[14] = 570 + 500;
	YPos[15] = 600 + 500;
	YPos[16] = 660 + 500;
	YPos[17] = 740 + 500;

}
bool CCreditsState::Input(void)
{
	if( CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN) || CSGD_DirectInput::GetInstance()->KeyPressed(DIK_ESCAPE))
	{
		CGame::GetInstance()->ChangeState( CMainMenuState::GetInstance() );
	}

	return true;
}
void CCreditsState::Update(float fElapsedTime)
{
	/*if( !CSGD_FModManager::GetInstance()->IsSoundPlaying(m_nBGM) )
		CSGD_FModManager::GetInstance()->PlaySound(m_nBGM);*/

	for (int index = 0; index < 18; index++)
	{
		//scroll up each of the credits
		YPos[index] -= (fElapsedTime * 0.1f);
		//loop back around when they finish showing at the top
		if (YPos[index] <= 0)
			YPos[index] = 1000;
	}
}
void CCreditsState::Render(void)
{
	
	char buffer[255];
	//CBitmapFont BF;

	CBitmapFont::GetInstance()->PrintText("Credits", 300, 25, D3DCOLOR_XRGB(255, 255, 255));

	//BF.PrintText("Credits", 10, YPos[0]/*10*/, 1.0f, D3DCOLOR_XRGB(255, 255, 255), true);
	//BF.PrintText("Main programming", 10, YPos[1]/*60*/,  0.65f, D3DCOLOR_XRGB(255, 255, 0), true);
	//BF.PrintText("Steven Seufert", 10, YPos[2]/*90*/,  0.65f, D3DCOLOR_XRGB(50, 50, 175), true);

	//BF.PrintText("Original Sprites", 10, YPos[3]/*150*/,  0.65f, D3DCOLOR_XRGB(255, 255, 0), true);	
	//BF.PrintText("www.pixeljoint.com", 10, YPos[4]/*180*/,  0.65f, D3DCOLOR_XRGB(50, 50, 175), true);
	//BF.PrintText("www.slateman.net", 10, YPos[5]/*210*/,  0.65f, D3DCOLOR_XRGB(50, 50, 175), true);
	//BF.PrintText("Touch-ups", 10, YPos[6]/*240*/,  0.65f, D3DCOLOR_XRGB(255, 255, 0), true);
	//BF.PrintText("Steven Seufert", 10, YPos[7]/*270*/,  0.65f, D3DCOLOR_XRGB(50, 50, 175), true);

	//BF.PrintText("Music", 10, YPos[8]/*330*/,  0.65f, D3DCOLOR_XRGB(255, 255, 0), true);
	//BF.PrintText("gh.ffshrine.org", 10, YPos[9]/*360*/,  0.65f, D3DCOLOR_XRGB(50, 50, 175), true);

	//BF.PrintText("Sound Effects", 10, YPos[10]/*420*/,  0.65f, D3DCOLOR_XRGB(255, 255, 0), true);
	//BF.PrintText("www.kyutwo.com", 10, YPos[11]/*450*/,  0.65f, D3DCOLOR_XRGB(50, 50, 175), true);

	//BF.PrintText("Special Thanks", 10, YPos[12]/*510*/,  0.65f, D3DCOLOR_XRGB(255, 255, 0), true);
	//BF.PrintText("David Brown", 10, YPos[13]/*540*/,  0.65f, D3DCOLOR_XRGB(50, 50, 175), true);
	//BF.PrintText("For his assistance and ", 10, YPos[14]/*570*/,  0.65f, D3DCOLOR_XRGB(50, 50, 175), true);
	//BF.PrintText("code managers", 10, YPos[15]/*600*/,  0.65f, D3DCOLOR_XRGB(50, 50, 175), true);

	//BF.PrintText("(c)2011 Steven Seufert", 100, YPos[16]/*660*/, 0.75f, D3DCOLOR_XRGB(50, 50, 175), true);

	//BF.PrintText("No ships were harmed in the making of this game", 100, YPos[17]/*700*/, 0.40f, D3DCOLOR_XRGB(50, 50, 175), true);
	
	//draw the cursor at the current selection
	//CSGD_TextureManager::GetInstance()->Draw(m_nCursorID, 200, 440 );
	
}
void CCreditsState::Exit(void)
{
	//TODO:
	CSGD_FModManager::GetInstance()->StopSound(m_nBGM);
	
	CSGD_FModManager::GetInstance()->UnloadSound(m_nBGM);
}